package wechat

import (
	"fmt"
	"net/http"

	"mall/service/pay/api/internal/logic/wechat"
	"mall/service/pay/api/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

func WechatRefundCallbackHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		l := wechat.NewWechatRefundCallbackLogic(r.Context(), svcCtx)
		resp, err := l.WechatRefundCallback(r)
		if err != nil {
			// logx.WithContext(r.Context()).Errorf("【API-ERR】 ThirdPartyPayment WechatRefundCallbackHandler : %+v ", err)
			logx.Errorw("【API-ERR】 ThirdPartyPayment WechatRefundCallbackHandler error", logx.Field("detail", err.Error()))
			w.WriteHeader(http.StatusBadRequest)
		} else {
			w.WriteHeader(http.StatusOK)
		}

		// logx.Infof("ReturnCode : %s ", resp.ReturnCode)
		logx.Errorw("ThirdPartyPayment WechatRefundCallbackHandler", logx.Field("returnCode", resp.ReturnCode))
		fmt.Fprint(w.(http.ResponseWriter), resp.ReturnCode)
	}
}
